home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / proged1.lha / InstallProgED / SASC_support / Sources / CreateSMakefile.c next >
C/C++ Source or Header  |  1995-09-20  |  5KB  |  258 lines

  1.  
  2. #include <proto/dos.h>
  3. #include <proto/exec.h>
  4. #include <exec/memory.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. #define MAXLEN    130
  10.  
  11. struct MyStruct {
  12. struct AnchorPath anc;
  13. char pad[MAXLEN];
  14. } s;
  15.  
  16.  
  17.  
  18. void FreeList(struct List *list)
  19. {
  20.     struct Node    *n;
  21.     if (list)
  22.     while(!IsListEmpty(list))
  23.     {
  24.         n=RemHead(list);
  25.         FreeVec(n->ln_Name);
  26.         FreeVec(n);
  27.     }
  28. }
  29.  
  30.  
  31.  
  32. void CreateList(struct List *list,char *pattern)
  33. {
  34.     int         err;
  35.     struct Node    *node;
  36.     char        *string;
  37.  
  38.  
  39.  
  40.     NewList(list);
  41.  
  42.     err=MatchFirst(pattern,(struct AnchorPath*)&s);
  43.     while(!err)
  44.     {
  45.         if (s.anc.ap_Info.fib_DirEntryType<0)
  46.         {
  47.             if (!(node=AllocVec(sizeof(struct Node),MEMF_CLEAR)))
  48.             {
  49.                 MatchEnd((struct AnchorPath*)&s);
  50.                 return;
  51.             }
  52.  
  53.             if (!(string=AllocVec(strlen(&s.anc.ap_Buf[0])+1,MEMF_CLEAR)))
  54.             {
  55.                 FreeVec(node);
  56.                 MatchEnd((struct AnchorPath*)&s);
  57.                 return;
  58.             }
  59.  
  60.             strcpy(string,&s.anc.ap_Buf[0]);
  61.             node->ln_Name=string;
  62.             AddTail(list,node);
  63.         }
  64.         err=MatchNext((struct AnchorPath*)&s);
  65.     }
  66.     MatchEnd((struct AnchorPath*)&s);
  67. }
  68.  
  69.  
  70.  
  71. void AddExt(char *nome,char *ext)
  72. {
  73.     char    *p=nome;
  74.  
  75.     p+=strlen(p)-1;
  76.  
  77.     while(p>=nome)
  78.     {
  79.         if (*p=='.')
  80.         {
  81.             strcpy(p+1,ext);
  82.             return;
  83.         }
  84.         p--;
  85.     }
  86.  
  87.     strcat(nome,".");
  88.     strcat(nome,ext);
  89. }
  90.  
  91.  
  92.  
  93. void main(int argc,char *argv[])
  94. {
  95.     struct List     C_List,
  96.              A_List,
  97.              H_List;
  98.     struct Node    *node,
  99.             *node2;
  100.     int         gst;
  101.     FILE        *file;
  102.     BPTR         dir;
  103.     char         buffer[MAXLEN+1],
  104.              curdir[MAXLEN+1];
  105.  
  106.  
  107.  
  108.  
  109.     if ((argc!=4)&&(argc!=2))
  110.     {
  111.         printf("SYNTAX: %s <Executable> [<GST> <PreInclude>]\n",argv[0]);
  112.         exit(5);
  113.     }
  114.  
  115.     if (argc==4)    gst=TRUE;
  116.     else        gst=FALSE;
  117.  
  118.     s.anc.ap_Strlen=MAXLEN;
  119.  
  120.     CreateList(&C_List,"#?.c");
  121.     CreateList(&A_List,"#?.a");
  122.     CreateList(&H_List,"#?.h");
  123.  
  124.     if (gst)
  125.     {
  126.         for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  127.             if (!stricmp(node->ln_Name,argv[3]))
  128.                 break;
  129.  
  130.         if (node->ln_Succ)
  131.         {
  132.             Remove(node);
  133.             FreeVec(node->ln_Name);
  134.             FreeVec(node);
  135.         }
  136.     }
  137.  
  138.     if (!(dir=Lock("",ACCESS_READ)))
  139.     {
  140.         printf("Can't lock current dir!\n");
  141.         exit(5);
  142.     }
  143.     NameFromLock(dir,curdir,sizeof(curdir)-1);
  144.     UnLock(dir);
  145.  
  146.     if (strlen(curdir)>0)
  147.         if ((curdir[strlen(curdir)-1]!=':')&&(curdir[strlen(curdir)-1]!='/'))
  148.             strcat(curdir,"/");
  149.  
  150.     if (!(file=fopen("SMakefile","w")))
  151.     {
  152.         FreeList(&C_List);
  153.         FreeList(&A_List);
  154.         FreeList(&H_List);
  155.         exit(5);
  156.     }
  157.  
  158.     fprintf(file,"\n");
  159.  
  160.     fprintf(file,"AFLAGS\t= -Iinclude:\n");
  161.  
  162.     fprintf(file,"\n");
  163.  
  164.     fprintf(file,"CFLAGS\t=\n");
  165.  
  166.     fprintf(file,"\n");
  167.  
  168.     fprintf(file,"LFLAGS\t=\n");
  169.  
  170.     fprintf(file,"\n");
  171.  
  172.     fprintf(file,"OBJS\t= ");
  173.     for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  174.     {
  175.         strcpy(buffer,node->ln_Name);
  176.         AddExt(buffer,"o");
  177.         fprintf(file,"%s ",buffer);
  178.     }
  179.     for(node=A_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  180.     {
  181.         strcpy(buffer,node->ln_Name);
  182.         AddExt(buffer,"o");
  183.         fprintf(file,"%s ",buffer);
  184.     }
  185.     fprintf(file,"\n");
  186.  
  187.     fprintf(file,"\n");
  188.  
  189.     fprintf(file,"LIBS\t= LIB:sc.lib LIB:amiga.lib\n");
  190.  
  191.     fprintf(file,"\n");
  192.  
  193.     if (gst)    fprintf(file,"all: %s %s\n",argv[2],argv[1]);
  194.     else        fprintf(file,"all: %s\n",argv[1]);
  195.  
  196.     fprintf(file,"\n");
  197.  
  198.     if (gst)
  199.     {
  200.         fprintf(file,"%s: PRJ:%s ",argv[2],argv[3]);
  201.         for(node=H_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  202.             fprintf(file,"PRJ:%s ",node->ln_Name);
  203.         fprintf(file,"\n");
  204.         fprintf(file,"\tSC:C/SC NOLINK ERRREXX OBJNAME T:Dummy.o MAKEGST=$@ PRJ:%s\n",argv[3]);
  205.         fprintf(file,"\tC:DELETE >NIL: T:Dummy.o\n");
  206.  
  207.         fprintf(file,"\n");
  208.     }
  209.  
  210.     fprintf(file,"%s: $(OBJS)\n",argv[1]);
  211.     fprintf(file,"\tSC:C/SLINK FROM LIB:c.o $(OBJS) TO $@ LIB $(LIBS) $(LFLAGS)\n");
  212.  
  213.     fprintf(file,"\n");
  214.  
  215.     for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  216.     {
  217.         strcpy(buffer,node->ln_Name);
  218.         AddExt(buffer,"o");
  219.         fprintf(file,"%s: PRJ:%s ",buffer,node->ln_Name);
  220.         strcpy(buffer,curdir);
  221.         AddPart(buffer,node->ln_Name,sizeof(buffer)-1);
  222.         AddExt(buffer,"o");
  223.         for(node2=H_List.lh_Head;node2->ln_Succ;node2=node2->ln_Succ)
  224.             fprintf(file,"PRJ:%s ",node2->ln_Name);
  225.         fprintf(file,"\n");
  226.  
  227.         fprintf(file,"\tSC:C/SC NOLINK ERRREXX $(CFLAGS) PRJ:%s OBJNAME %s",node->ln_Name,buffer);
  228.         if (gst)    fprintf(file," GST=%s GSTIMM\n",argv[2]);
  229.         else        fprintf(file,"\n");
  230.  
  231.         fprintf(file,"\n");
  232.     }
  233.     for(node=A_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
  234.     {
  235.         strcpy(buffer,node->ln_Name);
  236.         AddExt(buffer,"o");
  237.         fprintf(file,"%s: PRJ:%s ",buffer,node->ln_Name);
  238.         strcpy(buffer,curdir);
  239.         AddPart(buffer,node->ln_Name,sizeof(buffer)-1);
  240.         AddExt(buffer,"o");
  241.         for(node2=H_List.lh_Head;node2->ln_Succ;node2=node2->ln_Succ)
  242.             fprintf(file,"PRJ:%s ",node2->ln_Name);
  243.         fprintf(file,"\n");
  244.  
  245.         fprintf(file,"\tSC:C/ASM $(AFLAGS) -o%s PRJ:%s\n",buffer,node->ln_Name);
  246.         fprintf(file,"\n");
  247.     }
  248.     fprintf(file,"\n");
  249.  
  250.     fclose(file);
  251.  
  252.     FreeList(&C_List);
  253.     FreeList(&A_List);
  254.     FreeList(&H_List);
  255.  
  256.     exit(0);
  257. }
  258.